package com.kakarote.bi.service.dwhImpl;

import cn.hutool.core.util.ObjectUtil;
import com.kakarote.bi.entity.VO.BiOperateLogVO;
import com.kakarote.bi.mapper.BiLogMapper;
import com.kakarote.bi.service.BiLogService;
import com.kakarote.common.log.enums.ApplyEnum;
import com.kakarote.common.log.enums.BehaviorEnum;
import com.kakarote.common.log.enums.OperateObjectEnum;
import com.kakarote.core.entity.BasePage;
import com.kakarote.core.feign.crm.entity.BiOperateLogParams;
import com.kakarote.core.utils.UserCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

/**
 * @author: admin
 * @version: v1.0
 * @date:2023/8/15
 */
@Service
@ConditionalOnProperty(prefix = "bi", name = "clickhouse", havingValue = "true")
public class BiLogServiceImpl implements BiLogService {

    @Autowired
    private BiLogMapper biLogMapper;

    @Override
    public BasePage<BiOperateLogVO> queryOperationLogs(BiOperateLogParams biParams) {

        BasePage<BiOperateLogVO> data = biLogMapper.queryOperationLogs(biParams.parse(), biParams);

        for (BiOperateLogVO datum : data.getList()) {
            ApplyEnum parse = ApplyEnum.parse(datum.getApply());
            datum.setApplyName(parse.getRemarks());
            datum.setModuleName(OperateObjectEnum.parse(datum.getModule(), datum.getApply()).getRemarks());
            datum.setBehaviorName(BehaviorEnum.parse(datum.getBehavior()).getName());
            datum.setUserName(ObjectUtil.equal(0L, datum.getCreateUserId()) ? "系统自动操作" : UserCacheUtil.getUserName(datum.getCreateUserId()));
        }


        return data;
    }
}
